﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Castle.Components.DictionaryAdapter;
using System.Xml;

namespace Sio.Mdm.Web
{
    public static class XML
    {
        private static DictionaryAdapterFactory Adapter = new DictionaryAdapterFactory();
        public static Dictionary<string, object> Deserialize(string xml)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(String.Format("<data>{0}</data>", xml));

                foreach (XmlNode node in doc.FirstChild.ChildNodes)
                {
                    result.Add(node.Name, node.InnerText);
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return result;
        }
        public static T Deserialize<T>(string xml)
        {
            return Adapter.GetAdapter<T>(Deserialize(xml));
        }
    }
}
